function SheetUtils() {
};

SheetUtils.tasks = function(gui, user, date, data, callbackFunc, callbackFunc1, callbackFunc2) {
  var tr, td, popupBox = new ModulePopupBox(), _self = this;

  var tasks = data[0].data;
  var notes = data['note'];
  var models = data['pz_model'];
  var states = data['pz_model_state'];
  var transitions = data['pz_model_transition'];
  this._queue = data[0].queue;
  this._cond = data[0].condition;
  this._select = data['table_select'];
  this._join = data['table_join'];
  this._cultures = data['culture'].data;
  this._ceremonys = data['ceremony'].data;
  this._receptions = data['reception'].data;
  this._colors = data['color'].data;
  DOMUtils.removeTableRows(gui.main, 1);

  if (tasks.length == 0) {
    tr = gui.main.insertRow(-1);
    td = tr.insertCell(-1);
    td.colSpan = 28;
    td.style.height = '23px';
    td.style.textAlign = 'left';
    td.style.paddingLeft = '5px';
    td.appendChild(document.createTextNode('n/a'));
  }
  
  for(var i = 0, il = tasks.length; i < il; i++) {
    var task = tasks[i];
    tr = gui.main.insertRow(-1);
    tr.style.backgroundColor = (tr.rowIndex % 2 == 0) ? '#ececec' : '#fff';
    tr.style.color = (task.deadline && parseInt((task.deadline - date) / 86400, 10) <= 0) ? '#ff0000' : '#000000';

    td = tr.insertCell(-1);
    td.style.height = '23px';
    td.style.padding = '0 5px';
    td.style.borderRight = 'solid 1px #bbb';
    if(task.is_canceled == 1){
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode((task.branch) ? task.branch : '-'));
    
    td = tr.insertCell(-1);
    td.style.padding = '0 5px';
    td.style.borderRight = 'solid 1px #bbb';
    if(task.is_canceled == 1){
      td.style.textDecoration = 'line-through';
    }
    if (task.is_wedding == 1) {
      td.style.color = 'green';
    }
    td.appendChild(document.createTextNode((task.customer_id != 0) ? PPublishUtils.customerId(task.customer_id) : '-'));
    var note = document.createElement('button');
    var count = 0;
    for (var j = 0, jl = notes.length; j < jl; j++) {
      var n = notes[j];
      if (n.id == task.id) {
        count = n.value;
      }
    }
    note.className = (count == 0) ? 'notebtn' : 'notebtn1';
    note.style.margin = '0 0 0 5px';
    note._task = task;
    note.onclick = function() { var div = document.createElement('div');
                                var pos = DOMUtils.findPos(this);
                                var pub = (user.type == Constant.USER_TYPE_DESIGNER || user.type == Constant.USER_TYPE_MAILER || this._task.model_id != 1) ? true : false;
                                MiscUtils.dialog(popupBox, pos, div, null, null, { t: 'Details', width: 500, height: 50 });
                                new ModuleDialogPublish(document, div, 500, 30, user, date, { data: data, task: this._task, popupBox: popupBox, callback: callbackFunc, callback1: callbackFunc1, pos: pos, pub: pub });
                                return false;
                              };
                              
    td.appendChild(note);
    
    td = tr.insertCell(-1);
    td.style.padding = '0 5px';
    td.style.borderRight = 'solid 1px #bbb';
    if(task.is_canceled == 1){
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode(PPublishUtils.customerName(task.bride_name, task.groom_name)));
//    if(user.type == Constant.USER_TYPE_ADMINISTER || user.type == Constant.USER_TYPE_ASSISTANT){
//      var a = document.createElement('a');
//      a.href = '#';
//      a._task = task;
//      a.style.paddingLeft = '3px';
//      a.style.fontSize = '11px';
//      a.appendChild(document.createTextNode('Chg'));
//      a._task = task;
//      a.onclick = function() { var pos = DOMUtils.findPos(this);
//                               var div = document.createElement('div');
//                               var task = this._task;
//                               var func1 = function() { popupBox._close();
//                                                        task.customer_name = task._text;
//                                                        new RequestUtils()._write2([{ n: 'pz_task', a: [task], r: [] }], callbackFunc, { pos: pos });
//                                                      };
//                               var func2 = function() { popupBox._close();
//                                                        callbackFunc();
//                                                      };
//                               MiscUtils.dialog(popupBox, pos, div, func1, func2, { t: 'Update Customer Name', width: 500, height: 50 });
//                               new ModuleDialogInput(document, div, null, null, user, date, { object: task, dfault: task.customer_name, isText: true });
//                               return false;
//                             };
//      if (task.is_canceled != 1 && task.state_id < 15 && task.customer_name && task.customer_name != '') {
//        td.appendChild(a);
//      }
//    }
    
    td = tr.insertCell(-1);
    td.style.padding = '0 5px';
    td.style.borderRight = 'solid 1px #bbb';
    if(task.is_canceled == 1){
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode((task.culture1) ? task.culture1 : '-'));
//    if(user.type == Constant.USER_TYPE_ADMINISTER || user.type == Constant.USER_TYPE_ASSISTANT){
//      var a = document.createElement('a');
//      a.href = '#';
//      a._task = task;
//      a.style.paddingLeft = '3px';
//      a.style.fontSize = '11px';
//      a.appendChild(document.createTextNode('Chg'));
//      a._task = task;
//      a.onclick = function() { var pos = DOMUtils.findPos(this);
//                               var div = document.createElement('div');
//                               var task = this._task;
//                               var func1 = function() { popupBox._close();
//                                                        task.culture1 = task._text;
//                                                        new RequestUtils()._write2([{ n: 'pz_task', a: [task], r: [] }], callbackFunc, { pos: pos });
//                                                      };
//                               var func2 = function() { popupBox._close();
//                                                        callbackFunc();
//                                                      };
//                               MiscUtils.dialog(popupBox, pos, div, func1, func2, { t: 'Update Culture', width: 500, height: 50 });
//                               new ModuleDialogSelect(document, div, null, null, user, date, { object: task, dfault: task.culture1, objects: _self._cultures });
//                               return false;
//                             };
//      if (task.is_canceled != 1 && task.state_id < 15 && task.culture1 && task.culture1 != '') {
//        td.appendChild(a);
//      }
//    }
    
    td = tr.insertCell(-1);
    td.style.padding = '0 5px';
    td.style.borderRight = 'solid 1px #bbb';
    if(task.is_canceled == 1){
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode((task.culture2) ? task.culture2 : '-'));
//    if(user.type == Constant.USER_TYPE_ADMINISTER || user.type == Constant.USER_TYPE_ASSISTANT){
//      var a = document.createElement('a');
//      a.href = '#';
//      a._task = task;
//      a.style.paddingLeft = '3px';
//      a.style.fontSize = '11px';
//      a.appendChild(document.createTextNode('Chg'));
//      a._task = task;
//      a.onclick = function() { var pos = DOMUtils.findPos(this);
//                               var div = document.createElement('div');
//                               var task = this._task;
//                               var func1 = function() { popupBox._close();
//                                                        task.culture2 = task._text;
//                                                        new RequestUtils()._write2([{ n: 'pz_task', a: [task], r: [] }], callbackFunc, { pos: pos });
//                                                      };
//                               var func2 = function() { popupBox._close();
//                                                        callbackFunc();
//                                                      };
//                               MiscUtils.dialog(popupBox, pos, div, func1, func2, { t: 'Update Culture', width: 500, height: 50 });
//                               new ModuleDialogSelect(document, div, null, null, user, date, { object: task, dfault: task.culture2, objects: _self._cultures });
//                               return false;
//                             };
//      if (task.is_canceled != 1 && task.state_id < 15 && task.culture2 && task.culture2 != '') {
//        td.appendChild(a);
//      }
//    }
    
    td = tr.insertCell(-1);
    td.style.padding = '0 5px';
    td.style.borderRight = 'solid 1px #bbb';
    if(task.is_canceled == 1){
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode((task.ceremony) ? task.ceremony : '-'));
//    if(user.type == Constant.USER_TYPE_ADMINISTER || user.type == Constant.USER_TYPE_ASSISTANT){
//      var a = document.createElement('a');
//      a.href = '#';
//      a._task = task;
//      a.style.paddingLeft = '3px';
//      a.style.fontSize = '11px';
//      a.appendChild(document.createTextNode('Chg'));
//      a._task = task;
//      a.onclick = function() { var pos = DOMUtils.findPos(this);
//                               var div = document.createElement('div');
//                               var task = this._task;
//                               var func1 = function() { popupBox._close();
//                                                        task.ceremony = task._text;
//                                                        new RequestUtils()._write2([{ n: 'pz_task', a: [task], r: [] }], callbackFunc, { pos: pos });
//                                                      };
//                               var func2 = function() { popupBox._close();
//                                                        callbackFunc();
//                                                      };
//                               MiscUtils.dialog(popupBox, pos, div, func1, func2, { t: 'Update Ceremony', width: 500, height: 50 });
//                               new ModuleDialogSelect(document, div, null, null, user, date, { object: task, dfault: task.ceremony, objects: _self._ceremonys });
//                               return false;
//                             };
//      if (task.is_canceled != 1 && task.state_id < 15 && task.ceremony && task.ceremony != '') {
//        td.appendChild(a);
//      }
//    }
    
    td = tr.insertCell(-1);
    td.style.padding = '0 5px';
    td.style.borderRight = 'solid 1px #bbb';
    if(task.is_canceled == 1){
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode((task.reception) ? task.reception : '-'));
//    if(user.type == Constant.USER_TYPE_ADMINISTER || user.type == Constant.USER_TYPE_ASSISTANT){
//      var a = document.createElement('a');
//      a.href = '#';
//      a._task = task;
//      a.style.paddingLeft = '3px';
//      a.style.fontSize = '11px';
//      a.appendChild(document.createTextNode('Chg'));
//      a._task = task;
//      a.onclick = function() { var pos = DOMUtils.findPos(this);
//                               var div = document.createElement('div');
//                               var task = this._task;
//                               var func1 = function() { popupBox._close();
//                                                        task.reception = task._text;
//                                                        new RequestUtils()._write2([{ n: 'pz_task', a: [task], r: [] }], callbackFunc, { pos: pos });
//                                                      };
//                               var func2 = function() { popupBox._close();
//                                                        callbackFunc();
//                                                      };
//                               MiscUtils.dialog(popupBox, pos, div, func1, func2, { t: 'Update Reception', width: 500, height: 50 });
//                               new ModuleDialogSelect(document, div, null, null, user, date, { object: task, dfault: task.reception, objects: _self._receptions });
//                               return false;
//                             };
//      if (task.is_canceled != 1 && task.state_id < 15 && task.reception && task.reception != '') {
//        td.appendChild(a);
//      }
//    }
    
    td = tr.insertCell(-1);
    td.style.padding = '0 5px';
    td.style.borderRight = 'solid 1px #bbb';
    if(task.is_canceled == 1){
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode((task.wedding_color) ? task.wedding_color : '-'));
//    if(user.type == Constant.USER_TYPE_ADMINISTER || user.type == Constant.USER_TYPE_ASSISTANT){
//      var a = document.createElement('a');
//      a.href = '#';
//      a._task = task;
//      a.style.paddingLeft = '3px';
//      a.style.fontSize = '11px';
//      a.appendChild(document.createTextNode('Chg'));
//      a._task = task;
//      a.onclick = function() { var pos = DOMUtils.findPos(this);
//                               var div = document.createElement('div');
//                               var task = this._task;
//                               var func1 = function() { popupBox._close();
//                                                        task.wedding_color = task._text;
//                                                        new RequestUtils()._write2([{ n: 'pz_task', a: [task], r: [] }], callbackFunc, { pos: pos });
//                                                      };
//                               var func2 = function() { popupBox._close();
//                                                        callbackFunc();
//                                                      };
//                               MiscUtils.dialog(popupBox, pos, div, func1, func2, { t: 'Update Color', width: 500, height: 50 });
//                               new ModuleDialogSelect(document, div, null, null, user, date, { object: task, dfault: task.wedding_color, objects: _self._colors });
//                               return false;
//                             };
//      if (task.is_canceled != 1 && task.state_id < 15 && task.wedding_color && task.wedding_color != '') {
//        td.appendChild(a);
//      }
//    }
    
    td = tr.insertCell(-1);
    td.style.padding = '0 5px';
    td.style.borderRight = 'solid 1px #bbb';
    if(task.is_canceled == 1){
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode((task.photographer) ? task.photographer : '-'));
//    if(user.type == Constant.USER_TYPE_ADMINISTER || user.type == Constant.USER_TYPE_ASSISTANT){
//      var a = document.createElement('a');
//      a.href = '#';
//      a._task = task;
//      a.style.paddingLeft = '3px';
//      a.style.fontSize = '11px';
//      a.appendChild(document.createTextNode('Chg'));
//      a._task = task;
//      a.onclick = function() { var pos = DOMUtils.findPos(this);
//                               var div = document.createElement('div');
//                               var transition = this._transition;
//                               var state = this._state;
//                               var task = this._task;
//                               var oldTask = MiscUtils.clone(task);
//                               var e = null;
//                               var t = null;
//                               var func1 = function() { popupBox._close();
//                                                        func();
//                                                      };
//                               var func2 = function() { popupBox._close();
//                                                        task.photogrpaher_id = oldTask.photogrpaher_id;
//                                                        task.photogrpaher = oldTask.photogrpaher;
//                                                        callbackFunc();
//                                                      };
//                                var func = function() { new RequestUtils()._write2([{ n: 'pz_task', a: [task], r: [] }, { n: 'pz_task_event', a: [e], r: [] }, { n: 'pz_task_track', a: [t], r: [] }], callbackFunc, { pos: pos });
//                                                      };
//                               MiscUtils.dialog(popupBox, pos, div, func1, func2, { t: 'Pick a Photographer', width: 320, height: 50 });
//                               new ModuleDialogPickPhotographer(document, div, null, null, user, date, { object: task });
//                               return false;
//                             };
//      if (task.is_canceled != 1 && task.state_id < 15 && task.photographer && task.photographer != '') {
//        td.appendChild(a);
//      }
//    }
    
    td = tr.insertCell(-1);
    td.style.padding = '0 5px';
    td.style.borderRight = 'solid 1px #bbb';
    if(task.is_canceled == 1){
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode((task.photographer2) ? task.photographer2 : '-'));
//    if(user.type == Constant.USER_TYPE_ADMINISTER || user.type == Constant.USER_TYPE_ASSISTANT) {
//      var a = document.createElement('a');
//      a.href = '#';
//      a._task = task;
//      a.style.paddingLeft = '3px';
//      a.style.fontSize = '11px';
//      a.appendChild(document.createTextNode('Chg'));
//      a._task = task;
//      a.onclick = function() { var pos = DOMUtils.findPos(this);
//                               var div = document.createElement('div');
//                               var transition = this._transition;
//                               var state = this._state;
//                               var task = this._task;
//                               var oldTask = MiscUtils.clone(task);
//                               var e = null;
//                               var t = null;
//                               var func1 = function() { popupBox._close();
//                                                        func();
//                                                      };
//                               var func2 = function() { popupBox._close();
//                                                        task.photographer2_id = oldTask.photographer2_id;
//                                                        task.photographer2 = oldTask.photographer2;
//                                                        callbackFunc();
//                                                      };
//                                var func = function() { new RequestUtils()._write2([{ n: 'pz_task', a: [task], r: [] }, { n: 'pz_task_event', a: [e], r: [] }, { n: 'pz_task_track', a: [t], r: [] }], callbackFunc, { pos: pos });
//                                                      };
//                               MiscUtils.dialog(popupBox, pos, div, func1, func2, { t: 'Pick a Photographer', width: 320, height: 50 });
//                               new ModuleDialogPickPhotographer(document, div, null, null, user, date, { object: task, idx: 2 });
//                               return false;
//                             };
//      if (task.is_canceled != 1 && task.state_id < 15 && task.photographer2 && task.photographer2 != '') {
//        td.appendChild(a);
//      }
//    }
  
    td = tr.insertCell(-1);
    td.style.padding = '0 5px';
    td.style.borderRight = 'solid 1px #bbb';
    if(task.is_canceled == 1){
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode((task.designer) ? task.designer : '-'));
//    if(user.type == Constant.USER_TYPE_ADMINISTER || user.type == Constant.USER_TYPE_ASSISTANT) {
//      var a = document.createElement('a');
//      a.href = '#';
//      a._task = task;
//      a.style.paddingLeft = '3px';
//      a.style.fontSize = '11px';
//      a.appendChild(document.createTextNode('Chg'));
//      a._task = task;
//      a.onclick = function() { var pos = DOMUtils.findPos(this);
//                               var div = document.createElement('div');
//                               var transition = this._transition;
//                               var state = this._state;
//                               var task = this._task;
//                               var oldTask = MiscUtils.clone(task);
//                               var e = null;
//                               var t = null;
//                               var func1 = function() { popupBox._close();
//                                                        func();
//                                                      };
//                               var func2 = function() { popupBox._close();
//                                                        task.designer_id = oldTask.designer_id;
//                                                        task.designer = oldTask.designer;
//                                                        callbackFunc();
//                                                      };
//                                var func = function() { new RequestUtils()._write2([{ n: 'pz_task', a: [task], r: [] }, { n: 'pz_task_event', a: [e], r: [] }, { n: 'pz_task_track', a: [t], r: [] }], callbackFunc, { pos: pos });
//                                                      };
//                               MiscUtils.dialog(popupBox, pos, div, func1, func2, { t: 'Pick a designer', width: 320, height: 50 });
//                               new ModuleDialogPickDesigner(document, div, null, null, user, date, { object: task });
//                               return false;
//                             };
//      if (task.is_canceled != 1 && task.state_id < 15 && task.designer && task.designer != '') {
//        td.appendChild(a);
//      }
//    }
    
    td = tr.insertCell(-1);
    td.style.padding = '0 5px';
    td.style.borderRight = 'solid 1px #bbb';
    if(task.is_canceled == 1){
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode((task.wedding_date != 0) ? SimpleDate.format(SimpleDate.fromStamp(task.wedding_date)) : '-'));
    
    td = tr.insertCell(-1);
    td.style.padding = '0 5px';
    td.style.borderRight = 'solid 1px #bbb';
    if(task.is_canceled == 1){
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode((task.sent_date != 0) ? SimpleDate.format(SimpleDate.fromStamp(task.sent_date)) : '-'));
    
    
    td = tr.insertCell(-1);
    td.style.padding = '0 5px';
    td.style.borderRight = 'solid 1px #bbb';
    if(task.is_canceled == 1){
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode((task.received_date != 0) ? SimpleDate.format(SimpleDate.fromStamp(task.received_date)) : '-'));
    
    td = tr.insertCell(-1);
    td.style.padding = '0 5px';
    td.style.borderRight = 'solid 1px #bbb';
    if(task.is_canceled == 1){
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode((task.retouched_date != 0) ? SimpleDate.format(SimpleDate.fromStamp(task.retouched_date)) : '-'));
    
    td = tr.insertCell(-1);
    td.style.padding = '0 5px';
    td.style.borderRight = 'solid 1px #bbb';
    if(task.is_canceled == 1){
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode((task.published_date != 0) ? SimpleDate.format(SimpleDate.fromStamp(task.published_date)) : '-'));

    td = tr.insertCell(-1);
    td.style.padding = '0 5px';
    td.style.borderRight = 'solid 1px #bbb';
    if(task.is_canceled == 1){
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode((task.is_signed == 0) ? 'NO' : 'YES'));
    
    td = tr.insertCell(-1);
    td.style.padding = '0 5px';
    td.style.borderRight = 'solid 1px #bbb';
    if(task.is_canceled == 1){
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode((task.is_asst_backup == 0) ? 'NO' : 'YES'));
    
    td = tr.insertCell(-1);
    td.style.padding = '0 5px';
    td.style.borderRight = 'solid 1px #bbb';
    if(task.is_canceled == 1){
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode((task.is_asst_pickup == 0) ? 'NO' : 'YES'));
    
    td = tr.insertCell(-1);
    td.style.padding = '0 5px';
    td.style.borderRight = 'solid 1px #bbb';
    if(task.is_canceled == 1){
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode((task.is_asst_retouched == 0) ? 'NO' : 'YES'));
    
    td = tr.insertCell(-1);
    td.style.padding = '0 5px';
    td.style.borderRight = 'solid 1px #bbb';
    if(task.is_canceled == 1){
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode((task.is_admin_checked == 0) ? 'NO' : 'YES'));
    
    td = tr.insertCell(-1);
    td.style.padding = '0 5px';
    td.style.borderRight = 'solid 1px #bbb';
    if(task.is_canceled == 1){
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode((task.is_admin_retouched == 0) ? 'NO' : 'YES'));
    
    td = tr.insertCell(-1);
    td.style.padding = '0 5px';
    td.style.borderRight = 'solid 1px #bbb';
    if(task.is_canceled == 1){
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode((task.is_choose_designer == 0) ? 'NO' : 'YES'));
    
    td = tr.insertCell(-1);
    td.style.padding = '0 5px';
    td.style.borderRight = 'solid 1px #bbb';
    if(task.is_canceled == 1){
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode((task.is_des_retouched == 0) ? 'NO' : 'YES'));
    
    td = tr.insertCell(-1);
    td.style.padding = '0 5px';
    td.style.borderRight = 'solid 1px #bbb';
    if(task.is_canceled == 1){
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode((task.is_admin_sorted == 0) ? 'NO' : 'YES'));
    
    td = tr.insertCell(-1);
    td.style.padding = '0 5px';
    td.style.borderRight = 'solid 1px #bbb';
    if(task.is_canceled == 1){
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode((task.is_asst_arranged == 0) ? 'NO' : 'YES'));
    
    td = tr.insertCell(-1);
    td.style.padding = '0 5px';
    td.style.borderRight = 'solid 1px #bbb';
    if(task.is_canceled == 1){
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode((task.is_asst_received == 0) ? 'NO' : 'YES'));
    
    td = tr.insertCell(-1);
    td.style.padding = '0 5px';
    td.style.borderRight = 'solid 1px #bbb';
    if(task.is_canceled == 1){
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode((task.is_asst_published == 0) ? 'NO' : 'YES'));
    
    td = tr.insertCell(-1);
    td.style.padding = '0 5px';
    if (task.state_id != 1) {
      ModelUtils.btns1(task, models, states, transitions, td, user, date, callbackFunc, callbackFunc2);
    } else {
      td.appendChild(document.createTextNode('等待签收'));
    }
  }
};
